package com.cloudlead.utils.sms.impl;

import com.cloudlead.common.lang.CommonBusinessModules;
import com.cloudlead.common.lang.service.AbstractBaseService;
import com.cloudlead.utils.sms.SmsService;
import com.ruanwei.interfacej.SendResponse;
import com.ruanwei.interfacej.SmsClientSend;
import com.ruanwei.interfacej.SmsSendException;
import com.vcom.sms.SmsSendClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by Dean on 2015/4/23.
 */
@Service("SmsService")
public class SmsServiceImpl extends AbstractBaseService implements SmsService {
    @Value("${sms.url}")
    private String smsClientUrl;
    @Value("${sms.userid}")
    private String smsClientUserid;
    @Value("${sms.password}")
    private String smsClientPassword;

    public SmsServiceImpl() {
        super(CommonBusinessModules.sms);
    }

    private SmsSendClient client;

    @Override
    public void init() {
        super.init();
        client = new SmsSendClient(smsClientUserid, smsClientPassword, smsClientUrl);
    }

    @Override
    public void sendVerificationCode(String mobile, String message) {
        client.sendVerificationCode(mobile, message);
        logger.debug("Smd send [" + message + "] to mobile [" + mobile + "] Success.");
    }

    @Override
    public void send(String[] mobile, String message) {
        client.send(mobile, message);
        logger.debug("Smd send [" + message + "] to mobile [" + mobile + "] Success.");
    }
}
